#ifndef MCI_H_
#define MCI_H_
/*******************************************************************************
 * File name:     mci.h
 * Description:
 * Project:       mci_new
 * Target:        LPC2478
 * Compiler:      arm-none-eabi-gcc
 * Date:          28-05-2012
 * Author:        Kuba
 * Based on:      ---
 ******************************************************************************/

/*==============================================================================
 Includes
==============================================================================*/
# include "irq.h"
/*==============================================================================
 Defines
==============================================================================*/

/*==============================================================================
 Types
==============================================================================*/
enum mciDma {
   mciDMA_DISABLE,
   mciDMA_ENABLE
};
/*==============================================================================
 Globals
==============================================================================*/

/*==============================================================================
 Global function prototypes
==============================================================================*/
/*------------------------------------------------------------------------------
 function name:   mciInit
 description:     init MCI controller
 parameters:      IRQ priority
 returned value:  true or false
------------------------------------------------------------------------------*/
bool mciInit            (enum priority priority);

/*------------------------------------------------------------------------------
 function name:   mciCardInit
 description:     detect and init card. If you need DMA support for MCI call this
                   function with mciDMA_ENABLE parameter.
 parameters:      GPDMA support on/of
 returned value:  true or false
------------------------------------------------------------------------------*/
bool mciCardInit        (enum mciDma dma);

/*------------------------------------------------------------------------------
 function name:   mciCardInfo
 description:     display information about card
 parameters:      none
 returned value:  none
------------------------------------------------------------------------------*/
void mciCardInfo        (void);

/*------------------------------------------------------------------------------
 function name:   mciDmaWrite2Card
 description:     function writes n bytes from src address to card via GPDMA.
                   One write is always 512 * 32 bytes. For example:
                   if user needs to write 100 bytes, function rounds the number
                   to 16384 up. If user needs to write 17000 bytes, function
                   rounds the number to 32768 bytes (16384 * 2)
 parameters:      pointer to transmit (TX) buffer,
                  sector number (1 sector = 512 bytes * 32 blocks),
                  size in bytes
 returned value:  last written sector
------------------------------------------------------------------------------*/
int32 mciDmaWrite2Card  (uint8 *tx, uint32 sector, uint32 size);

/*------------------------------------------------------------------------------
 function name:   mciDmaReadCard
 description:     function reads n bytes from card via GPDMA
 parameters:      pointer to receive (RX) buffer,
                   sector number (1 sector = 512 bytes * 32 blocks),
                   size in bytes
 returned value:  last read sector
------------------------------------------------------------------------------*/
int32 mciDmaReadCard    (uint8 *rx, uint32 sector, uint32 size);

/*------------------------------------------------------------------------------
 function name:   mciPrgWrite2Card
 description:     function writes n bytes from src address to card via software.
                   One write is always 512 bytes. NOTE: before you use this function
                   make sure the card init function is called with mciDMA_DISABLE
                   argument: mciCardInit(mciDMA_DISABLE);
 parameters:      pointer to transmit (TX) buffer,
                  starting block,
                  size in blocks (1 block = 512 bytes)
 returned value:  last written block
------------------------------------------------------------------------------*/
int32 mciPrgWrite2Card  (const uint8 *tx, uint32 block, uint32 numberOfBlocks);

/*------------------------------------------------------------------------------
 function name:   mciPrgReadCard
 description:     function reads n bytes from card to RX buffer via software. One
                   read is always 512 bytes. NOTE:
                   1) before you use this function make sure the card init function
                   is called with mciDMA_DISABLE argument: mciCardInit(mciDMA_DISABLE);
                   2) make sure your RX buffer is 512 * numberOfBlock size, ohterwise
                   you overwrite memory.
 parameters:      pointer to receive (RX) buffer,
                  starting block,
                  size in blocks (1 block = 512 bytes)
 returned value:  last read block
------------------------------------------------------------------------------*/
int32 mciPrgReadCard    (uint8 *rx, uint32 block, uint32 numberOfBlocks);

/******************************************************************************
* END OF FILE
******************************************************************************/



#endif /* MCI_H_ */
